# Maintainer:  Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Contributor: carstene1ns <url/mail: arch carsten-teibes de>
# Contributor: Tai Chi Minh Ralph Eastwood <tcmreastwood@gmail.com>


_realname=physfs
pkgbase=mingw-w64-${_realname}-hg
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-hg
pkgver=r1363.a3dabf75a0d0
pkgrel=1
pkgdesc="A library to provide abstract access to various archives (development version)"
arch=('any')
url="https://icculus.org/physfs/"
license=('zlib')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             'mercurial')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
source=("hg+https://hg.icculus.org/icculus/physfs"
        "0000_pkgconfig.patch")
sha256sums=('SKIP'
            'b6f7657315cea4f183941efc7a537c8bc410ab7892ae5818786272e66e90a6b1')

pkgver() {
  cd ${srcdir}/${_realname}
  printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -Np1 -i ${srcdir}/0000_pkgconfig.patch

  # avoid abort in docs target
  sed -i 's/-Werror//' CMakeLists.txt
}

build() {
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DPHYSFS_BUILD_TEST=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DPHYSFS_BUILD_WX_TEST=OFF \
    ../${_realname}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}/LICENSE.txt \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
